/****************************************************************************************************************************
 * @File name:completest.c
 * @Author:sunshu
 * @Version:v1.00
 * @Date:2018/01/20
 * @Description:
 * @Others:
 * @Function List:
 * @History:
****************************************************************************************************************************/

#include "stm32f4xx_hal.h"
#include "short_test.h"
#include "open_test.h"
#include "test_seq.h"
#include "power.h"
#include "led.h"
#include "display.h"
#include "battery.h"
#include "result.h"
#include "completetest.h"


unsigned char TestBusyFlag = 0;
unsigned char DoubelDisplayFlag = 0;
extern uint8_t  u8LedResult;

//#ifdef _TIME_PRINT
//extern uint32_t USCount100;
//uint32_t Time0 = 0;
//#endif
unsigned char ShortTest(DisplayData* pLdata,DisplayData* pRdata);

/****************************************************************************************************************************
* @Functions:TestRun()
* @Description:measure all the configurated pins
* @Input:
* @Output:
* @Return:
* @Others:
* @History:
****************************************************************************************************************************/
void TestRun(void)
{
    unsigned char TestResult;

    DoubelDisplayFlag = 0;
    TestBusyFlag = 1;

//	#ifdef _TIME_PRINT
//	Time0 = USCount100;
//	#endif

    LedTask(TEST_START);
    TestResult = ShortTest(&Disp_L,&Disp_R);

    if(TestResult == (L_READY|R_READY))
    {
        if(OpenTest(&Disp_OPENL,&Disp_OPENR) == ERROR_NOCONNECT)
        {
            DispMode = UPDATE_MODE_LR;			//2 line input
            DispPage = 6;
        }
        else
        {
            DispMode = UPDATE_MODE_OK;			//SHORT and OPEN result
            DispPage = 6;
        }
    }
    else if(TestResult == L_READY)
    {
        DispMode = UPDATE_MODE_L;					//L input
        DispPage = 3;
    }
    else if(TestResult == R_READY)
    {
        DispMode = UPDATE_MODE_R;					//R input
        DispPage = 3;
    }
    else			//NO_CONNECT
    {
        DispMode = UPDATE_MODE_NC;				//nc
        DispPage = 0;
    }

    Short_TestCycle.Init();
    Display_TestResult();
    LedTask(u8LedResult);
    TestBusyFlag = 0;
    UsbPowerCount = 0;
}

